<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
  xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
  xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
  targetNamespace="Examples">

  <process id="process" isExecutable="true">

    <startEvent id="theStart" />

    <sequenceFlow sourceRef="theStart" targetRef="task1" />

    <userTask id="task1" />

    <sequenceFlow sourceRef="task1" targetRef="serviceTask" />

    <serviceTask id="serviceTask" camunda:expression="${true}" />

    <sequenceFlow sourceRef="serviceTask" targetRef="task2" />

    <userTask id="task2">
      <extensionElements>
        <camunda:taskListener event="create">
          <camunda:script scriptFormat="groovy">
            services = task.getProcessEngineServices();

            // fetch current authentication
            identityService = services.getIdentityService();
            task.setVariable('userId', identityService.getCurrentAuthentication().getUserId());

            // execute query
            runtimeService = services.getRuntimeService();
            task.setVariable('count', runtimeService.createProcessInstanceQuery().count());
          </camunda:script>
        </camunda:taskListener>
      </extensionElements>
    </userTask>

    <sequenceFlow sourceRef="task2" targetRef="theEnd" />

    <endEvent id="theEnd" />

  </process>

</definitions>